package com.diver.flinkdemo.utils.Trd;/**
 * @author yangs
 */

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.diver.flinkdemo.utils.xiaoyang.XiaoYangSignUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author yangs
 */
@Slf4j
public class XyRequestUtil {
    private static final String KEY = "TYLX";
    private static final String SECRET = "3DC3CEA682C1C999EC0E93016AA7A4AB";

//    public String PushDeviceCurpos(JSONObject params){
//
//    }
//
//    /**
//     * iccid
//     * @param params
//     * @return
//     */
//    public String pushDevICCID(JSONObject params){
//        return this.post("PushDevICCID", params);
//    }

    public String post(String url, JSONObject params){

        // sign
        String sign = XiaoYangSignUtil.sign(params, SECRET);

        // 公共参数
        params.put("KEY", KEY);
        params.put("SIGN", sign);
        params.put("TIMESTAMP", System.currentTimeMillis());

        Map<String, Object> map = (Map<String, Object>) JSON.parse(params.toJSONString());
//        String url1 = HttpUtil.urlWithForm(BASE_URL + url, m, Charset.defaultCharset(), false);
//        String pa = "BAT=54&DEVICENUM=865609040000881&GPS=3&LA=29.5497321q&LO=106.510284q&LOCTIME=2020-09-02 00:00:43&POSDESC=重庆天地" +
//                "&TIMESTAMP=1598500601&TYPE=1&SIGN=F2E643F50E4AA7F5D972A778C0593732&GSM=5";
        String paramsStr = HttpUtil.toParams(map);
        String result = HttpUtil.post(url, paramsStr);
        log.info("url:{}, 参数：{}, 结果: {}", url, params, result);
        return result;
    }
}
